package com.freshcity.component.alert
{
	import com.greensock.TimelineLite;
	import com.greensock.TweenLite;
	
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextFormat;
	
	public class Alert
	{
		public static const YES:int=1;
		
		public static const NO:int=2;
		
		public static const OK:int=4;
		
		public static const CANCEL:int=8;
		
		public static const Mode_None:String="none";
		
		public static const Mode_NoneNotModal:String="nonenotmodal";
		
		public static const Mode_Simple:String="simple";
		
		public static const Mode_Blur:String="blur";
		
		public static var okLabel:String="确定";
		
		public static var calcelLabel:String="取消";
		
		public static var yesLabel:String="是";
		
		public static var noLabel:String="否";
		
		public static var text:String="";
		
		public static var title:*;
		
		public static var buttonFlags:uint=0;
		
		public static var parent:DisplayObjectContainer;
		
		public static var titleColor:uint=16777215;
		
		public static var buttonColor:uint=5143985;
		
		public static var buttonTextColor:uint=16777215;
		
		public static var backgroundColor:uint=0;
		
		public static var backgroundAlpha:Number=0;
		
		public static var buttonStyleName:String;
		
		public static var titleTextFormat:TextFormat;
		
		public static var messageTextFormat:TextFormat;
		
		public static var mode:String="simple";
		
		public static var alertWinRenderer:Class=null;
		
		public static var timerOut:int=0;
		
		public static var timerNO:Boolean=false;
		
		public static var showCloseBtn:Boolean;
		
		private static var _defaultAlertWinRenderer:Class=null;
		
		private static var stage:*=null;
		
		private static var _instance:Alert;
		
		public static var buttonHeight:int=22;
		
		public static var textColor:uint=0;
		
		public static var buttonWidth:int=49;
		
		public static var defaultButtonFlag:uint=4;
		
		public static var iconClass:Class;
		
		public static var closeHandler:Function;
		
		public static var extendObj:Object;
		
		public function Alert(arg1:DisplayObjectContainer)
		{
			if (_instance != null) 
			{
				throw new Error(" AlertManager 单例 ");
			}
			stage = arg1;
		}
		
		public static function init(arg1:DisplayObjectContainer):void
		{
			if (_instance == null) 
			{
				_instance = new Alert(arg1);
			}
		}
		
		public static function get defaultAlertWinRenderer():Class
		{
			return _defaultAlertWinRenderer;
		}
		
		public static function set defaultAlertWinRenderer(arg1:Class):void
		{
			alertWinRenderer = arg1;
			_defaultAlertWinRenderer = arg1;
			return;
		}
		
		public static function resetToDefault():void
		{
			okLabel = "确定";
			calcelLabel = "取消";
			yesLabel = "是";
			noLabel = "否";
			text = "";
			title = null;
			buttonFlags = 0;
			parent = null;
			closeHandler = null;
			iconClass = null;
			defaultButtonFlag = 4;
			buttonWidth = 49;
			buttonHeight = 25;
			textColor = 0;
			titleColor = 16777215;
			buttonColor = 5143985;
			buttonTextColor = 16777215;
			backgroundColor = 0;
			backgroundAlpha = 0;
			titleTextFormat = null;
			messageTextFormat = null;
			alertWinRenderer = defaultAlertWinRenderer;
			mode = "simple";
			timerOut = 0;
			buttonStyleName = null;
			showCloseBtn = false;
			timerNO = false;
			extendObj = null;
			return;
		}
		
		
		
		public static function flick(arg1:DisplayObject):void
		{
			var obj:DisplayObject;
			var x:Number;
			var y:Number;
			var timeLite:TimelineLite;
			
			var loc1:*;
			timeLite = null;
			obj = arg1;
			x = obj.x;
			y = obj.y;
			timeLite = new TimelineLite();
			timeLite.append(new TweenLite(obj, 0.05, {"glowFilter":{"color":14540253, "alpha":0.5, "blurX":100, "blurY":100, "inner":true}}));
			timeLite.append(new TweenLite(obj, 0.05, {"glowFilter":{"color":14540253, "alpha":1, "blurX":1, "blurY":1, "inner":true}}));
			timeLite.append(new TweenLite(obj, 0.05, {"glowFilter":{"color":14540253, "alpha":0.5, "blurX":100, "blurY":100, "inner":true}}));
			timeLite.append(new TweenLite(obj, 0.05, {"glowFilter":{"color":14540253, "alpha":1, "blurX":1, "blurY":1, "inner":true}}));
			timeLite.append(new TweenLite(obj, 0.05, {"glowFilter":{"color":14540253, "alpha":0.5, "blurX":100, "blurY":100, "inner":true}}));
			timeLite.append(new TweenLite(obj, 0.05, {"glowFilter":{"color":14540253, "alpha":1, "blurX":1, "blurY":1, "inner":true}, "onComplete":function ():void
			{
				timeLite.stop();
				timeLite.kill();
				timeLite = null;
				return;
			}}))
			timeLite.play();
			return;
		}
		
		public static function show(text:String="", title:*="", flags:uint=4, parent:Sprite=null, closeHandler:Function=null, iconClass:Class=null, defaultButtonFlag:uint=4):Sprite
		{
			var myAlert:Sprite;
			var container:DisplayObjectContainer;
			var containerWidth:Number;
			var containerHeight:Number;
			
			var loc1:*;
			var clickHandler:Function = function (arg1:MouseEvent):void
			{
				var loc1:*=arg1.target as DisplayObject;
				var loc2:*=arg1.currentTarget as GAlertWin;
				if (!loc2.window.contains(loc1)) 
				{
					if (loc2.promptBackground) 
					{
						flick(loc2.promptBackground);
					}
				}
				return;
			}
			var removeHandler:Function = function (arg1:Event):void
			{
				myAlert.removeEventListener(Event.REMOVED_FROM_STAGE, removeHandler);
				myAlert.removeEventListener(MouseEvent.CLICK, clickHandler);
				return;
			}
			Alert.text = text;
			//Alert.title = title;
			Alert.title = "";
			Alert.buttonFlags = flags;
			if (parent) 
			{
				Alert.parent = parent;
			}
			Alert.closeHandler = closeHandler;
			if (iconClass) 
			{
				Alert.iconClass = iconClass;
			}
			Alert.defaultButtonFlag = defaultButtonFlag;
			if (!stage && !parent) 
			{
				throw new Error("AlertManager尚未初始化!必需指定Alert窗口显示的容器");
			}
			if (parent) 
			{
				containerWidth = parent.width;
				containerHeight = parent.height;
				container = parent;
			}
			else 
			{
				if (stage is Stage) 
				{
					containerWidth = stage.stageWidth;
					containerHeight = stage.stageHeight;
				}
				else if (stage is DisplayObjectContainer) 
				{
					containerWidth = stage.stage.stageWidth;
					containerHeight = stage.stage.stageHeight;
				}
				container = stage;
			}
			if (alertWinRenderer) 
			{
				myAlert = new alertWinRenderer(containerWidth, containerHeight);
			}
			else 
			{
				myAlert = new GAlertWin(containerWidth, containerHeight);
			}
			container.addChild(myAlert);
			
			if (myAlert is GAlertWin) 
			{
				myAlert.addEventListener(MouseEvent.CLICK, clickHandler);
				myAlert.addEventListener(Event.REMOVED_FROM_STAGE, removeHandler);
			}
			resetToDefault();
			return myAlert;
		}
	}
}